﻿using TickSharp.Core.Exceptions;
using TickSharp.Core.Interfaces;

namespace TickSharp.Core
{
    public static class IoC
    {        
        public static void Initialize(IDependencyResolver dependencyResolver)
        {
            if (_resolver != null)
            {
                throw new DuplicateInitializationException("IoC");
            }
            Resolver = dependencyResolver;
        }

        public static void Reset()
        {
            _resolver = null;
        }

        public static bool IsInitialized
        {
            get
            {
                return _resolver != null;
            }
        }
        
        public static IDependencyResolver Resolver
        {
            get
            {
                if (!IsInitialized)
                {
                    throw new NotInitializedException("IoC");
                }
                return _resolver;
            }
            private set
            {
                _resolver = value;
            }
        }

        private static IDependencyResolver _resolver;
    }
}
